﻿@model IEnumerable<com.fmtx.Model.PictureType>
@{
    ViewBag.Title = "Index";
    var isowner = Convert.ToInt32(Html.ViewContext.RouteData.Values["uid"]) == LoginModel.User.Uid;
}

<div class="container" >
    <fieldset>
        <legend style="font-size:inherit;" >
           <div class="control-group">
            <div class="controls" >
            相册列表  
            @if(isowner){
                <a style="margin-left:30px;" class="btn" rel="tooltip" data-original-title="新建文件夹" onclick="openAddPictypebox()"><i class="icon-folder-open"></i>添加</a>
            }
             </div>
        </div>
            </legend>
        <div class="control-group" style="margin-top:0px;">
            <ul class="unstyled userphoto">
                @if(Model!=null)
                {
                    foreach (var item in Model)
                    {
                        <li id="li_@item.Id" >
                            <a href="/@Html.ViewContext.RouteData.Values["uid"]/photo/detail/@item.Id" title="@item.Name" >
                                <img src="@StaticCs.ImageUrl/img/OnlyCache?m=OverCut&w=200&h=250&file=@item.FrontCover" />
                            </a>
                            <a>@item.Name</a>
                            @if(isowner){
                            <a style="line-height:20px;" onclick="delPicturetype(@item.Id)"><i class="icon-trash"></i>删除</a>
                            }
                        </li>
                    }
                }
            </ul>
        </div>
        </fieldset>
</div>
<div style="clear:both;"></div>

<script type="text/template" id="templatetype_add">
<div class="well" style="margin-bottom: 0px">
    <span style="position: absolute;top: -10px;right: -10px;cursor: pointer;" onclick="ClosemsgModal()"><img src="/css/images/x.png"/></span>
    <input id="txttype" placeholder="请输入文件夹名称" type="text" />
    <input type="button" class="btn" onclick="dosavePictype(this)" value="确定"/>
    </div>
</script>

@section scripts{
    @Scripts.Render("~/js/jqueryval")
    <script src="~/js/kindeditor/kindeditor-min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
        $("input[name=CityName]").fmtxDropdown({ url: "/action/area/CityBykey", value: "CityId" });
        $("input[name=PlaceName]").fmtxDropdown({
            url: "/action/area/PlaceBykey", value: "PlaceId", param: "input[name=CityId]", paramkey: "cityid", change: function (id, name) {
                $.get("/action/area/GetCityByPlace", { placeid: id }, function (data) {
                    $("input[name=CityName]").val(data.CityName);
                    $("input[name=CityId]").val(data.CityId);
                });
            }
        });


    });
    $(function () {
        var btn = $("#fat-btn")
        btn.click(function () {
            var text = $(this).attr("data-loading-text");
            btn.attr('data-loading-text', btn.text());
            btn.text(text);
            btn.attr("disabled", "disabled");
            btn.addClass("disabled");
            $("#f1").submit();
            setTimeout(function () {
                var text = btn.attr("data-loading-text");
                btn.attr('data-loading-text', btn.text());
                btn.text(text);
                btn.removeAttr("disabled");
                btn.removeClass("disabled");
            }, 2500)
        });
    })

    function openAddPictypebox() {
        showmsgmodalcontent($("#templatetype_add").html());
        $("#txttype").focus();
    }

    function dosavePictype(objthis) {
        var name = $("#txttype").val();
        $.getJSON("/Action/Picture/AddType?jsoncallback=?", { name: name }, function (data) {
            if (data.error == 0) {
                location.href = "/@Html.ViewContext.RouteData.Values["uid"]/photo/detail/" + data.id;
            } else {
                showerror(data.msg);
            }
        });

    }

    function delPicturetype(id) {
        setconfirm("确定要删除吗？", function () {
            showloading();
            $.post("/Action/Picture/DelPictrueType", { id: id }, function (data) {
                if (data.error == 0) {
                    showinfo("删除成功！");
                    $("#li_" + id).remove();
                } else if (data.error == 1001) {
                    showloginDialog();
                } else {
                    showerror("删除失败！");
                }
            });
        });
    }
    setucentmenu("photo");
</script>
}
 
